package com.shanghaionstar.discover.violation;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.ContentView;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.mag.thirds.TrafficViolationsEntity;
import com.onstar.cn.mag.thirds.VehicleViolationBean;
import com.shanghaionstar.R;
import com.shanghaionstar.discover.adapter.ViolationResultAdapter;
import com.shanghaionstar.swipe.SwipeActivity;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.weight.CommonNoDatasLayout;

/**
 * Created by 7828wc on 16/7/20.
 */
@ContentView(R.layout.discover_violation_result)
public class ViolationResultActivity extends SwipeActivity {
    @FindViewById
    private CommonNoDatasLayout no_datas_layout;
    @FindViewById
    private LinearLayout datas_layout;
    @FindViewById
    private ListView violation_list;
    @FindViewById
    private TextView tv_make_model, total_violation_counts, total_violation_score, total_violation_money;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        VehicleViolationBean violationBean = (VehicleViolationBean) getIntent().getSerializableExtra("violation");
        if (violationBean != null) {
            if (!CommonUtil.isNull(violationBean.getList()) && violationBean.getList().size() > 0) {
                tv_make_model.setText(ApplicationUtil.getInstance().getCarInfo());
                int money = 0, score = 0;

                for (TrafficViolationsEntity entity : violationBean.getList()) {
                    if (!CommonUtil.isNull(entity.getScore())) {
                        score += Integer.parseInt(entity.getScore());
                    }
                    if (!CommonUtil.isNull(entity.getPrice())) {
                        money += Integer.parseInt(entity.getPrice());
                    }
                }
                total_violation_score.setText(score + "");
                total_violation_money.setText(money + "");
                total_violation_counts.setText(violationBean.getList().size() + "");
                violation_list.setAdapter(new ViolationResultAdapter(violationBean.getList(), this));
            } else {
                no_datas_layout.setVisibility(View.VISIBLE);
                datas_layout.setVisibility(View.GONE);
            }
        } else {
            no_datas_layout.setVisibility(View.VISIBLE);
            datas_layout.setVisibility(View.GONE);
        }

    }

    @Override
    public BasePresenter getPresenter() {
        return null;
    }
}
